//
//  BGMessageTitleView.m
//  bigMall
//
//  Created by LTOVE on 16/7/25.
//  Copyright © 2016年 thinklev. All rights reserved.
//

#import "BGMessageTitleView.h"

@implementation BGMessageTitleView

+ (UIView *)initWidthFrame:(CGRect)frame andTitle:(NSString *)title andSecTitle:(NSString *)secTitle andIsTop:(BOOL)isTop
{
    BGMessageTitleView *view = [[BGMessageTitleView alloc]initWithFrame:frame];
    view.backgroundColor = [UIColor whiteColor];
    //设置蓝色标签
    [view setBlueLabelWithView:view andIstop:isTop];
    //设置大标题
    [view setBigTitleWithView:view andTitle:title];
    //设置副标题
    [view setSecTitleWithView:view andSecTitle:secTitle];
    if (!isTop) {
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, view.height - 1, view.width, 1)];
        label.backgroundColor = BGtextGraykColor;
        [view addSubview:label];
    }
    return view;
}
- (void)setBlueLabelWithView:(UIView *)view andIstop:(BOOL)isTop
{
    UILabel *label = [[UILabel alloc]init];
    label.height = view.height * 0.8;
    label.width = 5;
    label.hidden = YES;
    label.backgroundColor = [UIColor blueColor];
    label.center = CGPointMake(6, view.height * 0.5);
    [view addSubview:label];
}
- (void)setBigTitleWithView:(UIView *)view andTitle:(NSString *)title
{
    title = title == nil ? @"" :title;
    NSRange range = [title rangeOfString:@"】"];
    NSDictionary *attdict = @{
                              NSFontAttributeName:BGTitleSize,
                              NSForegroundColorAttributeName:textBlackColor
                              };
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc]initWithString:title attributes:attdict];
    UILabel *label = [[UILabel alloc]init];
    if (range.location != NSNotFound) {
        [attrStr addAttribute:NSForegroundColorAttributeName value:[UIColor orangeColor] range:NSMakeRange(0, range.location)];
        

        
        
    }
    label.attributedText = attrStr;
//    label.text = @"fsdfds";
    [label sizeToFit];
    label.x = 20;
    label.centerY = view.height * 0.5;
    [view addSubview:label];
}

- (void)setSecTitleWithView:(UIView *)view andSecTitle:(NSString *)secTitle
{
    UILabel * label = [[UILabel alloc]init];
    label.text = secTitle;
    label.textColor = BGtextGraykColor;
    label.font = BGContenttextSize;
    [label sizeToFit];
    label.centerY =  view.height * 0.5;
    label.x = view.width - label.width - BGMaginLeft;
    [view addSubview:label];
}

@end
